/**
 * 通量数据统计
 */
(function(window, angular, undefined){
	var module = angular.module('water.apps.WasteWater.ReportData.wasteWaterMonitorDataManager',  ['water.entity.monitorData','water.common.dateUtil','water.entity.wasteWater.wasteWaterMonitorData']);
	
	module.controller('wasteWaterMonitorDataManager',function($rootScope,$scope,$controller,$WasteWaterMonitorDataService){

		/**
		 * 参数集
		 */
		$scope.queryObject={}
		/**
		 * 站点查询参数，为all时，查询所有站点通量数据
		 * 默认为all
		 */
		$scope.serachType="all";
		
		/**
		 * 监听左侧列表选择
		 */
		$scope.$on('dataPramChanged', function(event, station) {	
			$scope.stationCode=station.MN;
			$scope.OnGetLisst();
	    });
		/**
		 * 查询单击事件
		 */
		$scope.OnGetLisst=function(){
			_getList();
		}
		/**
		 * 导出Word
		 */
		$scope.onExportExcelClick=function(){
			$scope.getQueryObject();
			$WasteWaterMonitorDataService.outWord($scope.queryObject);
		}
		/**
		 * 获取通量数据
		 */
		function _getList(){	
			$scope.getQueryObject();
			$WasteWaterMonitorDataService.getList($scope.queryObject).then(function(d){
				$scope.monitorDataList = d;
			});
		}
		$scope.OnSerachType=function(Serach){
			$scope.serachType=Serach;
			_getList();
		}
		/**
		 * 获取查询参数
		 * forExcel 是否用于导出
		 */
		$scope.getQueryObject = function(){
			$scope.queryObject.waterType=getWaterType();
			$scope.queryObject.CODE=$scope.stationCode;
			if($scope.serachType=="all"){
				delete $scope.queryObject.CODE;
			}
			if($scope.dataType == "month"){
				var date = new Date();
				date.setFullYear($scope.selectYear);
				date.setMonth(parseInt($scope.selectMonth) - 1);
				date.setDate(1);
				date.setMonth(parseInt($scope.selectMonth));
				$scope.queryObject.start =$scope.selectYear + "-" + $scope.selectMonth + "-01" + " 00:00:00";
				//获取每个月最后一天
				var end_day = new Date($scope.selectYear,$scope.selectMonth,0); 
				$scope.queryObject.end =$scope.selectYear + "-" + $scope.selectMonth + "-"+end_day.getDate() + " 23:59:59";
			}
			$scope.queryObject.Month=$scope.selectMonth;
			return $scope.queryObject;
		}
		//初始化日期
		$scope.initQuery = function(dataType){
			$scope.dataType = dataType;
			if($scope.dataType == "day"){
				$scope.numLimit=13;
			}
			else if($scope.dataType == "month"){
				$scope.numLimit=7;
			}
			// 周查询条件，其中年份是公用的
			$scope.yearlist=[];
			var currentYear=(new Date()).getFullYear();
			for(var i=0;i<4;i++){
				$scope.yearlist.push({
					name:currentYear-i+"年",
					value:currentYear-i+""
				});
			}; 
			$scope.selectYear=currentYear+"";
			// 月查询条件
			$scope.monthlist=[];
			for(var i=1;i<=12;i++){
				$scope.monthlist.push({
					name:i+"月",
					value:""+i
				});
			};
			$scope.selectMonth=((new Date()).getMonth() + 1)+"";
			$scope.OnGetLisst();
		};
		function _init(){
			$scope.initQuery("month");
		}
		_init();
	});
}(window, angular));	